<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>智游公寓系统 - 用户信息添加</title>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/main.css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/lib/font-awesome/css/font-awesome.css">
</head>
<body>
<div class="box">
	<h3>添加用户信息</h3>
	<form action="${pageContext.request.contextPath}/UserAddServlet" method="post">
	<table class="form-table">
		<tr>
			<td>用户账号</td>
			<td colspan="3" class="control">
				<input type="text" name="u_name" id = "u_name" onblur="fun1()" placeholder="用户账号"> 
				<span id = "span1"></span>
			</td>
		</tr>
		<tr>
			<td>账号密码</td>
			<td colspan="3" class="control">
				<input type="text" name="u_pass" placeholder="账号密码">
			</td>
		</tr>
		<tr>
			<td>用户名称</td>
			<td colspan="3" class="control">
				<input type="text" name="u_realname" placeholder="用户名称">
			</td>
		</tr>
		<tr>
			<td>用户性别</td>
			<td colspan="3" class="control">
				<input type="text" name="u_sex" placeholder="用户年龄">
			</td>
		</tr>
		
		
	</table>
	<div class="buttons">
		<input class="btn btn-primary va-bottom" type="submit" value="保存">&nbsp;&nbsp;
		<a class="btn btn-default" href="javascript:history.go(-1)">返回</a>
	</div>
	</form>
	<script type="text/javascript">
	if(!(typeof(<%=request.getAttribute("msg") %>)=="object")){
		alert("${msg }")
	}
		
	function fun1(){
		var a = getXMLHttpRequest();
		var name = document.getElementById("u_name").value;
		var c = document.getElementById("span1");
		a.open("POST" , "/ap/CheckUserNameServlet" ,true);
		a.onreadystatechange = function(){
			if(a.readyState == 4 && a.status == 200){
				if(a.responseText == 1){
					c.innerHTML = "<font color = 'green'> 账户名可用 </font>";
				}else{
					c.innerHTML = "<font color = 'red'> 账户名已存在 </font>";
				}
					
			}
		}
		a.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		a.send("u_name="+name);
		
		
	}
	function getXMLHttpRequest() { 
		var xmlHttpReq; 
		try { // Firefox, Opera 8.0+, Safari 
			xmlHttpReq = new XMLHttpRequest(); 
		} catch (e) { 
			try {// Internet Explorer 
				xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP"); 
			} catch (e) { 
				try { 
					xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); 
				} catch (e) {} 
			} 
		} 
		return xmlHttpReq; 
		} 
	</script>
</div>
</body>
</html>